/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#ifndef INCLUDE_SHADER_MESH
#define INCLUDE_SHADER_MESH


#include "shader_line.h"



#ifdef __cplusplus

#include <basic_vec.h>
#include <matXX.h>

using uint = unsigned int;
using uint = uint32;

#define in
#define out
#define inout


#else

#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

#define Inline

#endif




struct S_MeshDrawProp {
	uint MeshPropOffset;
	uint MatrixOffset;
	uint ColorPropOffset;
	uint BonesOffset;
};

struct S_RayIntersectionMemProp {
	uint64_t m_Address_Origin;
	uint64_t m_Address_Direction;
	uint64_t m_Address_RayLength;

	uint64_t m_Address_IntersectionPoint;
	uint64_t m_Address_IntersectionDis;


	uint mem_OriginNum;
	uint mem_DirectionNum;
	uint mem_RayLengthNum;
	uint mem_IntersectionPointNum;
	uint mem_IntersectionDisNum;
	
	uint mem_Flage;

};


struct S_MeshPick {
	uint VertOffset;
	uint IndexOffset;
};


struct S_Pick {
	mat4 matrix;
	vec4 s;
	vec4 dir;
	uint vertOffset;
	uint indexOffset;
};







#ifdef __cplusplus

Inline vec3 f_lineMeshTranform(const vec3& point, const S_MeshTranformProp& prop, const mat4& ModelMat, const mat3& viewInverseMat) {
	vec3 coord;
	switch (prop.m_TransformMode) {
		case DEF_MESH_LINE_TRANFORMTYPEMODEL_ZAxialZoom: {
			coord.x = point.x * prop.m_XScale;
			coord.y = point.y * prop.m_YScale;
			coord.z = point.z * prop.m_ZScale;
			break;
		}
		case DEF_MESH_LINE_TRANFORMTYPEMODEL_CAMERAGAZE: {
			coord = viewInverseMat * point;
			break;
		}
		case DEF_MESH_LINE_TRANFORMTYPEMODEL_PointLink: {
			coord = point * vec3{prop.m_XMove, prop.m_YMove, prop.m_ZMove};
			coord += vec3{ModelMat.m3.x, ModelMat.m3.y, ModelMat.m3.z};
			break;
		}
		default:
			coord = point;
	}
	return coord;
}

#else

vec3 f_lineMeshTranform(in vec3 point, in S_MeshTranformProp prop, in mat4 ModelMat, in mat3 viewInverseMat, int mode) {
	vec3 coord;
	switch (mode) {
	case DEF_MESH_LINE_TRANFORMTYPEMODEL_CAMERAGAZE: {
		coord = viewInverseMat * point;
		break;
	}
	case DEF_MESH_LINE_TRANFORMTYPEMODEL_PointLink: {
		coord = point * vec3(prop.m_XMove, prop.m_YMove, prop.m_ZMove);
		coord += ModelMat[3].xyz;
		break;
	}
	}
	return coord;
}

#endif




#undef in
#undef out





#endif




